# Contributor: Kaarle Ritvanen <kunkku@alpinelinux.org>
# Maintainer: Kaarle Ritvanen <kunkku@alpinelinux.org>
pkgname=awall
pkgver=1.12.3
pkgrel=2
pkgdesc="Alpine Wall"
url="https://gitlab.alpinelinux.org/alpine/awall"
_luaver=5.4
arch="noarch"
license="GPL-2.0-only"
replaces="awall-nat"
depends="drill ipset iptables lua$_luaver lua$_luaver-alt-getopt
	lua$_luaver-cjson lua$_luaver-pc lua$_luaver-posix lua-schema
	lua$_luaver-stringy lua$_luaver-lyaml xtables-addons"
subpackages="$pkgname-masquerade $pkgname-policies"
triggers="$pkgname.trigger=/usr/share/awall"
source="https://gitlab.alpinelinux.org/alpine/awall/-/archive/v$pkgver/awall-v$pkgver.tar.bz2
	0001-iptables-fix-compat-with-legacy.patch
	awall-init
	setup-firewall
	"
builddir=$srcdir/awall-v$pkgver

build() {
	sed -i -e "1,1s:lua:lua$_luaver:" awall-cli
}

check() {
	make LUA_VERSION=$_luaver check
}

package() {
	make "ROOT_DIR=$pkgdir" LUA_VERSION=$_luaver install
	install -D "$srcdir"/awall-init "$pkgdir"/usr/libexec/awall-init
}

masquerade() {
	depends=awall
	for file in lua/$_luaver/awall/modules/masquerade.lua awall/mandatory/masquerade.json; do
		local path=usr/share/$file
		install -d "$subpkgdir/$(dirname $path)"
		mv "$pkgdir/$path" "$subpkgdir/$path"
	done
}

policies() {
	depends=awall
	local dir=usr/share/awall/optional
	install -d "$subpkgdir"/$dir
	mv "$pkgdir"/$dir/*.json "$subpkgdir"/$dir
	install -D "$srcdir"/setup-firewall "$subpkgdir"/usr/sbin/setup-firewall
}

sha512sums="
2c2b3e5b6d6e67809e20a13861e50110dc3a021f1c9aff5c3cdb92dcd6998494ae56469334d78c833228022772ced4b05367bb92be7e8a3c7a437420cdba6074  awall-v1.12.3.tar.bz2
deef6a4f62cd345d4f76cd53de98f1a6ecf18f81e89a7d528afc36b8e45aac9f2fc0370c2a3ffe6cb4aaab48a698088f9b8334d241d014ec2c29943bfecf066d  0001-iptables-fix-compat-with-legacy.patch
e83ea3281c298092530e45fa5b62f6f85b9e5109b11e109799465ea832608294c7d9c4c3f5b0f321dfc0e82040daf3a17d066e9dea65cb0dbae2c453ea9e62cd  awall-init
c701db48209f992c3cae88951dd02283ed40412fab684c3ef7186e909168bfa8d052afe639dd3b6bae32d51e84823c5b7f75313c9bdddb163c59894f8710e1ae  setup-firewall
"
